# Julia Schule-Cloos Copyright (c) 2023
FROM rocker/tidyverse:4.1.3

# Path to the replaction files in the docker container
ENV REPLICATION_PATH=/home/rstudio/misinfo_replication

# Set user, workdir, disable authentication and give user root privileges
USER root
WORKDIR /home/rstudio
ENV DISABLE_AUTH=true
ENV ROOT=true

# # Install system dependencies for R 
RUN apt-get update && apt-get install -y \
 libudunits2-dev \
 r-base-dev \
 libcurl4-openssl-dev \
 libssl-dev \
 libxml2-dev \
 libjpeg-dev \
 libpng-dev \
 libicu-dev \
 libfreetype6-dev \
 zlib1g-dev \
 make \
 pandoc \
 libnode-dev \
 libfontconfig1-dev \
 imagemagick \
 libmagick++-dev \
 gsfonts \ 
 libfreetype6-dev \
 curl \
 gdebi

# Install R package manager renv and pacman
RUN R -e "install.packages('renv')"
RUN R -e "install.packages('pacman')"

# Copy renv.lock file into container
COPY ./renv.lock ./renv.lock

# Install all dependencies based on renv.lock file
RUN R -e "renv::restore()"

# Install quarto for rendering the file
ARG QUARTO_VERSION="1.3.433"
RUN curl -o quarto-linux-amd64.deb -L https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.deb
RUN gdebi --non-interactive quarto-linux-amd64.deb

# copy files
COPY ./data $REPLICATION_PATH/data/
COPY ./src $REPLICATION_PATH/src/
COPY ./Schulte-Cloos_Fast-Paced_Fake-News_Replication.qmd $REPLICATION_PATH/Schulte-Cloos_Fast-Paced_Fake-News_Replication.qmd
COPY ./Schulte-Cloos_Fast-Paced_Fake-News_Replication.html $REPLICATION_PATH/Schulte-Cloos_Fast-Paced_Fake-News_Replication.html


# Change ownership of replication files to 'rstudio' user to allow rendering the file
RUN chown -R rstudio $REPLICATION_PATH && \
    chgrp -R rstudio $REPLICATION_PATH
